// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  if (event.code == 2) {
    let res = await db.collection('list_1').where({
      openid: wxContext.OPENID
    }).get()
    return res
  }
  if (event.code == 5) {
    res = await db.collection('views').aggregate().lookup({
      from: 'list_1',
      localField: 'id',
      foreignField: '_id',
      as: 'getId',
    }).end()
    // return res
    let arr = res.list.filter(item=>{
      return item.myid == wxContext.OPENID
    })
    return arr
  }
  if (event.code == 3) {
    let res = await db.collection('list_1').where({
      openid: wxContext.OPENID,
      recipeTypeId: event.id
    }).get()
    return res
  }
}